<template>
    <div>
        <el-row>
            <el-col :span="18">
                <el-button v-if="menuId==='5153'" @click="dialogShow('insert')" class="slot-btn-top" type="primary" size="small">发放任务</el-button>
                <el-button v-if="menuId==='5153'" @click="dialogShow('insertSH')" class="slot-btn-top" type="primary" size="small">发放售后采购任务</el-button>
                <el-popover placement="bottom-start" width="1000" style="box-shadow: 0 0 8px rgba(0,0,0,.5);" trigger="click">
                    <el-form :inline="true" :model="search">
                        <el-form-item label="令号">
                            <el-input v-model="search.makeNo"  ></el-input>
                        </el-form-item>
                        <el-form-item label="订单号">
                        <el-input v-model="search.orderNums"  ></el-input>
                        </el-form-item>
                        <el-form-item label="供应商名称">
                            <el-autocomplete  class="inputSuffix"  v-model="search.supplier" :fetch-suggestions="searchAsyncSupplier" placeholder="请输入供应商名称" @select="changeSupplier"></el-autocomplete>
                        </el-form-item>
                        <el-button type="primary" @click="searchData" icon="el-icon-search">查询</el-button>
                    </el-form>
                    <el-button slot="reference" type="primary">查询</el-button>
                </el-popover>
            </el-col>
            <el-col :span="6" v-if="menuId==='5158'">
                <el-tag type="success">总金额：{{totals}}</el-tag>
            </el-col>
        </el-row>
        <el-table :data="dataList" :highlight-current-row="true" stripe border class="table-index" :height="tableHeight" style="width: 100%;" :header-cell-style="getRowClass" :row-class-name="tableRowClassName">
            <el-table-column fixed type="index" label="*"  min-width="40"></el-table-column>
            <el-table-column prop="makeNo" label="令号" sortable width="60"></el-table-column>
            <el-table-column prop="supplierName.name" label="供应商名称" sortable min-width="270"></el-table-column>
            <el-table-column prop="cgTaskDetail" label="采购物品名称" sortable  min-width="140"></el-table-column>
            <el-table-column prop="lateOrderTime" label="计划到达时间" sortable   width="60"  :formatter="timesFormatter"></el-table-column>

            <el-table-column prop="isStart" label="任务是否接收" sortable  width="60" align ='center'>
                <template  slot-scope="scope">
                    <span :class="scope.row.isStart===1?'el-icon-circle-check cl-success':''"></span>
                </template>
            </el-table-column>
            <el-table-column prop="isStockUp" label="供方开始备货" sortable width="60" align ='center'>
                <template  slot-scope="scope">
                    <span :class="scope.row.isStockUp===1?'el-icon-circle-check cl-success':''"></span>
                </template>
            </el-table-column>
            <el-table-column prop="isCheckUp" label="备货过程是否检查" sortable width="70" align ='center'>
                <template  slot-scope="scope">
                    <span :class="scope.row.isCheckUp===1?'el-icon-circle-check cl-success':''"></span>
                </template>
            </el-table-column>
            <el-table-column prop="isDeliver" label="供方是否发货" sortable   width="60" align ='center'>
                <template  slot-scope="scope">
                    <span :class="scope.row.isDeliver===1?'el-icon-circle-check cl-success':''"></span>
                </template>
            </el-table-column>
            <el-table-column prop="isArrive" label="物料是否到货" sortable  width="60" align ='center'>
                <template  slot-scope="scope">
                    <span :class="scope.row.isArrive===1?'el-icon-circle-check cl-success':''"></span>
                </template>
            </el-table-column>
             <el-table-column prop="isReceiveInvoice" label="是否收到发票" sortable   width="60" align ='center'>
                <template  slot-scope="scope">
                    <span :class="scope.row.isReceiveInvoice===1?'el-icon-circle-check cl-success':''"></span>
                </template>
             </el-table-column>
             <el-table-column prop="isPay" label="货款是否已结" sortable    width="60" align ='center'>
                 <template  slot-scope="scope">
                    <span :class="scope.row.isPay===1?'el-icon-circle-check cl-success':''"></span>
                </template>
             </el-table-column>
            <el-table-column prop="supplierName.paymentMethod" label="付款方式" sortable width="100" :formatter="paymentMethodFormatter"></el-table-column>
            <el-table-column prop="paySum" label="货款结算金额" sortable width="60"></el-table-column>
            <el-table-column prop="totals" label="总金额" sortable width="100" v-if="menuId==='5158'"></el-table-column>
            <el-table-column prop="kfPersonName" label="库管人员" sortable width="100"></el-table-column>
            <el-table-column prop="cgPersonName" label="采购人员" sortable  width="100"></el-table-column>
            <el-table-column prop="cwPersonName" label="财务人员" sortable width="100"></el-table-column>
            <el-table-column prop="invoiceCode" label="发票号" sortable min-width="130"></el-table-column>
            <el-table-column fixed="right" label="操作"  align="center" width="160">
                <template slot-scope="scope">
                    <el-button @click="dialogShow('update',scope.row)" type="text" size="small">编辑</el-button>
                    <span  v-if="menuId==='5153'">
                        <el-button @click="sendMail(scope.row)" type="text" size="small" v-if="scope.row.isSendEmail===1">重新邮件</el-button>
                        <el-button @click="sendMail(scope.row)" type="text" size="small" v-else>发送邮件</el-button>
                    </span>
                    <el-button @click="showDialog2('order',scope.row)" type="text" size="small" v-if="menuId==='5153'">打印订货通知单</el-button>
                    <el-button @click="showDialog2('apply',scope.row)" type="text" size="small" v-if="menuId==='5158'">打印付款申请表</el-button>

                </template>

            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagination.currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"></el-pagination>
        <!-- 详情信息 -->
        <el-dialog :title="dialog.title" width="90%" top="30px" :visible.sync="dialog.isShow" :close-on-click-modal="false" v-dialogDrag>
            <el-tabs v-model="dialog.activeName" @tab-click="handleClick" style="padding-bottom: 15px;">
                <el-tab-pane label="任务信息" name="1" class="dialog1" :style="dialogHeightPane">
                    <!---->
                    <h3 class="dialog-plate-title"><span>基本信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialog.fromData" label-position="right" label-width="180px">
                        <el-form-item label="订单号"><el-input v-model="dialog.fromData.ordernums" :disabled="!dialog.fromDisable.ordernums"></el-input></el-form-item>
                        <el-form-item label="令号"><el-input v-model="dialog.fromData.makeNo" :disabled="!dialog.fromDisable.makeNo" ></el-input></el-form-item>
                        <el-form-item label="商品名称"><el-input v-model="dialog.fromData.cgTaskDetail" :disabled="!dialog.fromDisable.cgTaskDetail"></el-input></el-form-item>
                        <el-form-item label="供应商名称">
                             <el-autocomplete  class="inputSuffix"  v-model="dialog.fromData.supplierName.name" v-if="dialog.fromData.supplierName" :fetch-suggestions="asyncSupplier" placeholder="请输入供应商名称" @select="changeSupplier1" :disabled="!dialog.fromDisable.supplierName"></el-autocomplete>
                        </el-form-item>
                        <el-form-item label="任务发布人"><el-input v-model="dialog.fromData.creatorName" :disabled="!dialog.fromDisable.creatorName"></el-input></el-form-item>
                        <el-form-item label="任务发布时间"><el-input v-model="dialog.fromData.createTime" :disabled="!dialog.fromDisable.createTime" ></el-input></el-form-item>
                        <el-form-item label="采购人员"><el-select v-model="dialog.fromData.cgPerson" :disabled="!dialog.fromDisable.cgPerson">
                            <el-option v-for="item in purchases" :key="item.user_id" :value="item.user_id" :label="item.name"></el-option></el-select>
                        </el-form-item>
                    </el-form>

                    <!---->
                    <h3 class="dialog-plate-title"><span>启动信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialog.fromData" label-position="right" label-width="180px">
                        <el-form-item label="任务是否接收">
                            <el-select v-model="dialog.fromData.isStart" :disabled="!dialog.fromDisable.isStart" @change="change2Time('isStart','startTime')">
                                <el-option :value="1" label="是"></el-option>
                                <el-option :value="0" label="否"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="任务接收时间"><el-input v-model="dialog.fromData.startTime" :disabled="!dialog.fromDisable.startTime"></el-input></el-form-item>
                    </el-form>

                    <!---->
                    <h3 class="dialog-plate-title"><span>发货信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialog.fromData" label-position="right" label-width="180px">
                        <el-form-item label="供应商是否开始备货">
                            <el-select v-model="dialog.fromData.isStockUp" :disabled="!dialog.fromDisable.isStockUp" @change="change2Time('isStockUp','stockUpTime')">
                                <el-option :value="1" label="是"></el-option>
                                <el-option :value="0" label="否"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="开始备货创建时间"><el-input v-model="dialog.fromData.stockUpTime" :disabled="!dialog.fromDisable.stockUpTime"></el-input></el-form-item>
                        <el-form-item label="供应商备货过程是否检查">
                            <el-select v-model="dialog.fromData.isCheckUp" :disabled="!dialog.fromDisable.isCheckUp"  @change="change2Time('isCheckUp','checkUpTime')">
                                <el-option :value="1" label="是"></el-option>
                                <el-option :value="0" label="否"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="过程检查创建时间"><el-input v-model="dialog.fromData.checkUpTime" :disabled="!dialog.fromDisable.checkUpTime"></el-input></el-form-item>
                        <el-form-item label="供应商是否发货">
                            <el-select v-model="dialog.fromData.isDeliver" :disabled="!dialog.fromDisable.isDeliver" @change="change2Time('isDeliver','deliverTime')">
                                <el-option :value="1" label="是"></el-option>
                                <el-option :value="0" label="否"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="发货创建时间"><el-input v-model="dialog.fromData.deliverTime" :disabled="!dialog.fromDisable.deliverTime"></el-input></el-form-item>
                    </el-form>

                    <!---->
                    <h3 class="dialog-plate-title"><span>收货信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialog.fromData" label-position="right" label-width="180px">
                        <el-form-item label="货物是否已到">
                            <el-select v-model="dialog.fromData.isArrive" disabled @change="change2Time('isArrive','arriveTime')">
                                <el-option :value="1" label="是"></el-option>
                                <el-option :value="0" label="否"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="收货日期"><el-date-picker v-model="dialog.fromData.arriveTime" disabled type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="库房人员">
                            <el-select v-model="dialog.fromData.kfPerson" disabled><el-option v-for="item in rooms" :key="item.user_id" :value="item.user_id" :label="item.name"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-form>

                    <!---->
                    <h3 class="dialog-plate-title"><span>财务信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialog.fromData" label-position="right" label-width="180px">
                        <el-form-item label="货款是否已结">
                            <el-select v-model="dialog.fromData.isPay" :disabled="!dialog.fromDisable.isPay"  @change="change2Time('isPay','payAddTime')">
                                <el-option :value="1" label="是">
                                </el-option><el-option :value="0" label="否"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="付款金额"><el-input v-model="dialog.fromData.paySum" :disabled="!dialog.fromDisable.paySum"></el-input></el-form-item>
                        <el-form-item label="付款日期"><el-date-picker v-model="dialog.fromData.payTime" :disabled="!dialog.fromDisable.payTime" type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="付款填写时间"><el-input v-model="dialog.fromData.payAddTime" :disabled="!dialog.fromDisable.payAddTime"></el-input></el-form-item>
                        <el-form-item label="发票是否已到">
                            <el-select v-model="dialog.fromData.isReceiveInvoice" :disabled="!dialog.fromDisable.isReceiveInvoice" @change="change2Time('isReceiveInvoice','receiveInvoiceAddTime')">
                                <el-option :value="1" label="是"></el-option>
                                <el-option :value="0" label="否"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="发票号"><el-input v-model="dialog.fromData.invoiceCode" :disabled="!dialog.fromDisable.invoiceCode"></el-input></el-form-item>
                        <el-form-item label="发票金额"><el-input v-model="dialog.fromData.invoicesum" :disabled="!dialog.fromDisable.invoicesum"></el-input></el-form-item>
                        <el-form-item label="收发票日期"><el-date-picker v-model="dialog.fromData.receiveInvoiceTime" :disabled="!dialog.fromDisable.receiveInvoiceTime" type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="收发票填写时间"><el-input v-model="dialog.fromData.receiveInvoiceAddTime" :disabled="!dialog.fromDisable.receiveInvoiceAddTime"></el-input></el-form-item>
                        <el-form-item label="财务人员"><el-select v-model="dialog.fromData.cwPerson" :disabled="!dialog.fromDisable.cwPerson">
                            <el-option v-for="item in finance" :key="item.user_id" :value="item.user_id" :label="item.name"></el-option></el-select>
                        </el-form-item>
                        <el-form-item label="任务完成时间"><el-input v-model="dialog.fromData.taskFinishTime" :disabled="!dialog.fromDisable.taskFinishTime"></el-input></el-form-item>
                    </el-form>
                    <h3 class="dialog-plate-title"><span>凭证上传</span></h3>
                     <el-row>
                        <el-col :span="12" >
                            <el-col :span="4" class="labelTitle">支付凭证：</el-col>
                            <el-col :span="18" class="uploadImg">
                            <el-upload
                                class="avatar-uploader"
                                :action="actionUrl"
                                :show-file-list="false"
                                :on-success="handleAvatarSuccess1"
                                :before-upload="beforeAvatarUpload">
                                <img v-if="dialog.fromData.payEvidence" :src="dialog.fromData.payEvidence" class="avatar">
                                <i v-else class="el-icon-plus avatar-uploader-icon">支付凭证</i>
                            </el-upload>
                            </el-col>
                        </el-col>
                        <el-col :span="12">
                             <el-col :span="4" class="labelTitle">收货凭证：</el-col>
                             <el-col :span="18" class="uploadImg">
                                <el-upload
                                    class="avatar-uploader"
                                    :action="actionUrl"
                                    :show-file-list="false"
                                    :on-success="handleAvatarSuccess2"
                                    :before-upload="beforeAvatarUpload">
                                    <img v-if="dialog.fromData.receiveEvidence" :src="dialog.fromData.receiveEvidence" class="avatar">
                                    <i v-else class="el-icon-plus avatar-uploader-icon">收货凭证</i>
                                </el-upload>
                             </el-col>
                        </el-col>
                    </el-row>
                    <div style="text-align: center">
                        <el-button @click="submitList" type="primary">确 定</el-button>
                    </div>
                </el-tab-pane>
                <el-tab-pane v-if="dialogType !== '1'" label="任务详情" name="2" :style="dialogHeightPane">
                    <el-button @click="showDialog1('insert')" type="primary" size="small">新增</el-button>
                    <el-table :data="processStateData.slice((pagination1.currentPage-1)*pagination1.pageSize,pagination1.currentPage*pagination1.pageSize)" stripe border class="table-index" :height="dialogTableHeight" style="width: 100%;" :header-cell-style="getRowClass">
                        <el-table-column fixed type="index" label="*"  min-width="40" sortable></el-table-column>
                        <el-table-column prop="bomNameName" label="物料名称" sortable min-width="140"></el-table-column>
                        <el-table-column prop="type" label="型号" sortable   min-width="100"></el-table-column>
                        <el-table-column prop="nums" label="计划数量" sortable width="60"></el-table-column>
                        <el-table-column prop="price" label="计划单价" sortable width="60"></el-table-column>
                        <el-table-column prop="total" label="计划总价" sortable  width="60"></el-table-column>
                        <el-table-column prop="planArriveTime" sortable label="计划到达时间"  width="70" :formatter="timesFormatter"></el-table-column>
                        <el-table-column prop="planPayTime"  sortable label="计划支付时间" width="70" :formatter="timesFormatter"></el-table-column>
                         <el-table-column prop="planOrderTime" sortable label="下单时间"  width="70" :formatter="timesFormatter"></el-table-column>
                        <el-table-column prop="actNums" sortable label="实际数量" width="60">
                            <template  slot-scope="scope">
                                <span v-text="scope.row.actNums===0?'':scope.row.actNums"></span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="actPrice" sortable label="实际单价" width="60"></el-table-column>
                        <el-table-column prop="actTotal" sortable label="实际总价"  width="60"></el-table-column>
                        <el-table-column prop="use" label="用途"  sortable min-width="90" :formatter="formatDityUse"></el-table-column>
                        <el-table-column prop="isBuy" label="是否到货"  sortable  width="60" :formatter="formatDityUse">
                            <template  slot-scope="scope">
                                <span :class="scope.row.isBuy===1?'el-icon-circle-check cl-success':''"></span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="createTime" label="创建时间" sortable  min-width="140"></el-table-column>
                        <el-table-column prop="creatorName" label=" 创建人" sortable min-width="140"></el-table-column>
                        <el-table-column fixed="right" label="操作" sortable align="center" width="120">
                            <template slot-scope="scope">
                                <el-button @click="deleteBack(scope.row)" type="text" size="small">重新审核</el-button>
                                <el-button @click="showDialog1('update',scope.row)" type="text" size="small">编辑
                                </el-button>
                                 <el-button @click="clickArrive(scope.row)" type="text" size="small" v-if="scope.row.isBuy!==1&&role.ROLE_operation_cg_kf">到货
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination background @size-change="handleSizeChange1" @current-change="handleCurrentChange1" :current-page="pagination1.currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagination1.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="processStateData.length"></el-pagination>
                </el-tab-pane>
            </el-tabs>
        </el-dialog>
         <!-- 过程状态信息 -->
        <el-dialog :title="dialog1.title" width="900px" center :visible.sync="dialog1.isShow" :close-on-click-modal="false" style="padding-bottom: 15px;" v-dialogDrag>
            <el-form :inline="true" class="demo-form-inline" v-model="dialog1.fromData" label-position="right" label-width="180px">
                <el-form-item label="物料名称">
                     <el-autocomplete  class="inputSuffix"  v-model="dialog1.fromData.bomNameName" :fetch-suggestions="asyncBom" placeholder="请输入物料名称" @select="changebom" :disabled='dialog1.title==="修改"'></el-autocomplete>
                </el-form-item>
                <el-form-item label="规格型号"><el-input v-model="dialog1.fromData.type" :disabled='dialog1.title==="修改"'></el-input></el-form-item>
                <el-form-item label="计划数量"><el-input v-model="dialog1.fromData.nums" :disabled='dialog1.title==="修改"'></el-input></el-form-item>
                <el-form-item label="计划单价"><el-input v-model="dialog1.fromData.price" :disabled='dialog1.title==="修改"'></el-input></el-form-item>
                <el-form-item label="计划总价"><el-input v-model="dialog1.fromData.total" :disabled='dialog1.title==="修改"'></el-input></el-form-item>
                <el-form-item label="计划到达时间"><el-date-picker v-model="dialog1.fromData.planArriveTime" type="date" placeholder="选择日期" style="width: 200px;" :disabled='dialog1.title==="修改"'></el-date-picker></el-form-item>
                <el-form-item label="计划支付时间"><el-date-picker v-model="dialog1.fromData.planPayTime" type="date" placeholder="选择日期" style="width: 200px;" :disabled='dialog1.title==="修改"'></el-date-picker></el-form-item>
                <el-form-item label="实际数量"><el-input v-model="dialog1.fromData.actNums" :disabled="!role.ROLE_operation_cg_kf"></el-input></el-form-item>
                <el-form-item label="商品实际单价"><el-input v-model="dialog1.fromData.actPrice" :disabled="!role.ROLE_operation_cg_cg"></el-input></el-form-item>
                <el-form-item label="商品实际总价"><el-input v-model="dialog1.fromData.actTotal" disabled></el-input></el-form-item>
                 <el-form-item label="用途">
                    <el-select v-model="dialog1.fromData.use" >
                        <el-option value="" label="【空】"></el-option>
                        <el-option :value="0" label="耗材生产"></el-option>
                        <el-option :value="1" label="机器生产"></el-option>
                        <el-option :value="2" label="售后服务"></el-option>
                        <el-option :value="3" label="其他"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="备注"><el-input v-model="dialog1.fromData.remark"></el-input></el-form-item>
                <el-form-item label="创建时间"><el-input v-model="dialog1.fromData.createTime" disabled></el-input></el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: center;">
                <el-button @click="submitProcessStateList" type="primary">确 定</el-button>
            </div>
        </el-dialog>
        <div style="display:none">
            <order-notice :pid="dialog2.id" ref="print1"></order-notice>
            <payment-settlement :pid="dialog2.id" ref="print2"></payment-settlement>
        </div>
    </div>
</template>
<script>
import cgbHttp from '@/axios/cgbHttp.js'
import baseHttp from '@/axios/baseHttp.js'
import orderNotice from './task/orderNotice.vue'
import paymentSettlement from './task/paymentSettlement.vue'
export default {
    components:{
        "order-notice":orderNotice,
       "payment-settlement":paymentSettlement
    },
    data(){
        let menuId = sessionStorage.getItem('menuId');
        let roleList = JSON.parse(localStorage.getItem('roles'));
        let role = {
                ROLE_operation_cg_cg:false,
                ROLE_operation_cg_kf:false,
                ROLE_operation_cg_cw:false
            }
        roleList.forEach(item=>{
            if(item.role_code==='ROLE_operation_cg_cg'){
                role.ROLE_operation_cg_cg=true;
            }
            if(item.role_code==='ROLE_operation_cg_kf'){
                role.ROLE_operation_cg_kf= true;
            }
            if(item.role_code==='ROLE_operation_cg_cw'){
                role.ROLE_operation_cg_cw=true;
            }
        })
        return {
            totals:0.00,
            role:role,
            menuId: menuId,
            actionUrl:baseHttp.imgUpload(),/**图片上传接口 */
            search:{
                makeNo:'',
                orderNums:'',
                supplier:'',
                supplierId:''
            },
            payTypeList:[],/**所有付款方式 */
            dataList:[],
            allSupplier:[],
            pagination:{
                currentPage:1,
                pageSize:10,
                total:0
            },
            tableHeight:document.documentElement.clientHeight - 170,
            dialogHeightPane: {
                height: (document.documentElement.clientHeight - 180) + 'px',
                overflowY: 'auto'
            },
            dialogTableHeight: document.documentElement.clientHeight - 280,
            dialog:{
                title:'',
                isShow:false,
                activeName:'1',
                fromData:{},
                fromDisable:{}
            },
            processStateData:[],
            purchases:[],
            rooms:[],
            finance:[],
            notesRecordData:[],
            dialogType: '',
            pagination1:{
                currentPage:1,
                pageSize:10,
            },
            pagination2:{
                currentPage:1,
                pageSize:10,
            },
            dialog1:{
                title:'',
                isShow:false,
                fromData:{}
            },
            dialog2:{
                id:''
            },
            getPaymentSettlement:null
        }
    },
    created(){
        let self = this;
        cgbHttp.supplierAllList().then(res=>{
            /**获取所有供应商列表 */
            if(res.content.length>0){
                res.content.forEach(el => {
                    el.value =el.name;
                    self.allSupplier.push({
                        name:el.name,
                        value:el.name,
                        id:el.id
                    });
                });
            }
    })
    cgbHttp.supplierCode(6).then(res=>{
            /**获取付款方式 */
            res.content.forEach(element => {
            element.code = Number( element.code)
        });
        self.payTypeList = res.content;
        self.getTableData();
    })

    self.getPurchase();
    self.getRoom();
    self.getFinance();
    },
    methods:{
        timesFormatter(row, column, cellValue, index){
            return cellValue?this.timestampToTime1(cellValue,'mm-dd'):'';
        },
        getTableData(){
            let self = this;
            let data = {
                currentPage:self.pagination.currentPage,
                pageSize:self.pagination.pageSize,
                makeNo:self.search.makeNo,
                orderNums:self.search.orderNums,
                supplier:self.search.supplier===''?'':self.search.supplierId
            }
            switch(self.menuId){
                case '5153':
                    data.state=0;
                    break
                 case '5157':
                    data.state=0;
                    data.isArrive=0;
                    break
                case '5158':
                    data.state=0;
                    data.isPay=0
                    break
                case '5155':
                    data.state=1;
                    break
            }
            cgbHttp.cgtaskList(data).then(res=>{
                res.content.records.forEach(el=>{
                    let currentData =new Date().getTime();
                      el.timeWaring= el.lateOrderTime!==null&&(new Date(el.lateOrderTime).getTime()-currentData<86400000)&&self.menuId==='5153'?'warning-row':'';
                })
                self.dataList= res.content.records;
                self.pagination.total= res.content.total;
            })
            if(self.menuId==='5158'){
                cgbHttp.cgTaskTotal(data).then(res=>{
                   self.totals = res.content;
                })
            }

        },
         formatDityUse:function(row, column, cellValue, index) {
                return cellValue == '0' ? '耗材生产' : (cellValue == '1' ? '机器生产' : (cellValue == '2' ? '其他' : ''));
            },
        dialogShow(type,row){
            let self = this;
            self.dialog.isShow = true;
            switch(type){
                case "insert":
                    self.dialog.title='发放任务';
                    self.dialogType='1';
                    self.dialog.fromData={
                        supplierName:{
                            name:''
                        }
                    }
                    break;
                case "insertSH":
                     self.dialog.title='发放售后采购任务';
                     self.dialogType='1';
                     self.dialog.fromData={
                        supplierName:{
                            name:''
                        }
                    }
                    break;
                case "update":
                    self.dialogType='';
                     self.dialog.title='修改任务信息'
                     self.dialog.fromData =row
                    break;
            }
            self.dialog.activeName='1';
            self.dialog.fromDisable={
                orderNums:self.dialogType==='1'?true:false,
                supplierName:self.dialogType==='1'?true:false,
                creatorName:false,
                createTime:false,
                makeNo:false,
                cgTaskDetail:false,
                lateOrderTime:false,
                cgPerson:self.menuId==='5153'?true:false,
                isStart:self.role.ROLE_operation_cg_cg?true:false,
                startTime:self.role.ROLE_operation_cg_cg?true:false,
                isStockUp:self.role.ROLE_operation_cg_cg?true:false,
                stockUpTime:self.role.ROLE_operation_cg_cg?true:false,
                isCheckUp:self.role.ROLE_operation_cg_cg?true:false,
                checkUpTime:self.role.ROLE_operation_cg_cg?true:false,
                isDeliver:self.role.ROLE_operation_cg_cg?true:false,
                deliverTime:self.role.ROLE_operation_cg_cg?true:false,
                isArrive:self.role.ROLE_operation_cg_kf?true:false,
                arriveTime:self.role.ROLE_operation_cg_kf?true:false,
                arriveAddTime:self.role.ROLE_operation_cg_kf?true:false,
                kfPerson:self.role.ROLE_operation_cg_kf?true:false,
                isPay:self.role.ROLE_operation_cg_cw?true:false,
                paySum:self.role.ROLE_operation_cg_cw?true:false,
                payTime:self.role.ROLE_operation_cg_cw?true:false,
                payAddTime:self.role.ROLE_operation_cg_cw?true:false,
                isReceiveInvoice:self.role.ROLE_operation_cg_cw?true:false,
                invoiceCode:self.role.ROLE_operation_cg_cw?true:false,
                receiveInvoiceTime:self.role.ROLE_operation_cg_cw?true:false,
                receiveInvoiceAddTime:self.role.ROLE_operation_cg_cw?true:false,
                cwPerson:self.role.ROLE_operation_cg_cw?true:false,
                invoicesum:self.role.ROLE_operation_cg_cw?true:false,
                taskFinishTime:self.role.ROLE_operation_cg_cw?true:false,
            }

        },
        searchAsyncSupplier(queryString, callback){
            let results = queryString ?  this.allSupplier.filter(this.createStateFilter(queryString)) : this.allSupplier;
            callback(results);
        },
        asyncSupplier(queryString, callback){
             let results = queryString ?  this.allSupplier.filter(this.createStateFilter(queryString)) : this.allSupplier;
            callback(results);
        },
        asyncBom(queryString, callback){
             let result=[];
            cgbHttp.searchMaterialKeyWord({name:queryString}).then(res=>{
                if(res.content&&res.content.length>0){
                    res.content.forEach(element => {
                        element.value = element.name;
                    });
                }
                result = res.content;
                callback(result);
            })
        },
        changebom(item){
            this.dialog1.fromData.bomName=item.id;
            this.dialog1.fromData.bomNameName = item.value;
            this.dialog1.fromData.type=item.type
        },
        createStateFilter(queryString) {
            return (state) => {
                return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) !==-1);
            };
        },
        changeSupplier(item){
            this.search.supplier=item.value;
            this.search.supplierId = item.id;
        },
        changeSupplier1(item){
            this.dialog.fromData.supplier = item.id;
        },
        tableRowClassName(data){
            return data.row.timeWaring;
        },
        searchData(){
            this.pagination.currentPage = 1;
            this.getTableData();
        },
        handleSizeChange(size){
            this.pagination.pageSize = size;
            this.getTableData();
        },
        handleCurrentChange(current){
            this.pagination.currentPage = current;
            this.getTableData();
        },
        handleSizeChange1(size){
            this.pagination1.currentPage=1;
            this.pagination1.pageSize = size;
        },
        handleCurrentChange1(currentPage){
            this.pagination1.currentPage=currentPage;
        },
        handleClick(tab, event){
            let self = this;
            switch(tab.name){
                case '2':
                    self.getProcessStateData();
                    break;
                case '3':
                    break;
            }
        },
        getPurchase() {/** 获取采购人员列表*/
            let self = this;
            cgbHttp.purchasesPersonList({roleid:128}).then(res=>{
                    self.purchases = res.content;
            })
        },
        getRoom() {/** 获取库房人员列表*/
            let self = this;
            cgbHttp.purchasesPersonList({roleid:129}).then(res=>{
                    self.rooms = res.content;
            })
        },
        getFinance() {/** 获取财务人员列表*/
            let self = this;
            cgbHttp.purchasesPersonList({roleid:130}).then(res=>{
                    self.finance = res.content;
            })
        },
        submitList(){
            let self = this;
            self.dialog.fromData.startTime = self.dialog.fromData.startTime?self.timestampToTime1(self.dialog.fromData.startTime,'yy-mm-dd hh:mm:ss'):null;
            self.dialog.fromData.payTime=self.dialog.fromData.payTime?self.timestampToTime1(self.dialog.fromData.payTime,'yy-mm-dd hh:mm:ss'):null;
            self.dialog.fromData.receiveInvoiceTime=self.dialog.fromData.receiveInvoiceTime?self.timestampToTime1(self.dialog.fromData.receiveInvoiceTime,'yy-mm-dd hh:mm:ss'):null;
                if(self.dialog.title==='发放售后采购任务'){
                    cgbHttp.addShCgTask(self.dialog.fromData).then(res=>{
                        self.dialog.isShow = false;
                        self.getTableData();
                        self.$message.success(`${self.dialog.title}成功`);
                    })
                }else{
                    let type = self.dialog.title==='发放任务'?'insert':'update';
                    cgbHttp.addUpdateCgtask(type,self.dialog.fromData).then(res=>{
                        self.dialog.isShow = false;
                        self.getTableData();
                        self.$message.success(`${self.dialog.title}成功`);
                    })
                }

        },
        showDialog1(type,row){
            let self = this;
            self.dialog1.title = type==='insert'?'新增':'修改';
            self.dialog1.isShow = true;
            self.dialog1.fromData=type==='insert'?{}:row;
            self.dialog1.fromData.actNums = type==='insert'?'':(self.dialog1.fromData.actNums===0?'':self.dialog1.fromData.actNums)
        },
        change2Time( isOk ,eTime){
            if ( this.dialog.fromData[isOk] == 1) {
                let date = new Date();
                let Y = date.getFullYear() + '-';
                let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + " ";
                let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ":";
                let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ":";
                let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                this.dialog.fromData[eTime] =  Y + M + D + h + m + s;
            }else{
                this.dialog.fromData[eTime] = '';
            }
        },
        getProcessStateData(){
            let self = this;
            cgbHttp.cgTaskDetailList(self.dialog.fromData.id).then(res=>{
               self.processStateData=res.content;
            })
        },
        submitProcessStateList(){
            let self = this;
            let type = self.dialog1.title==='新增'?'insert':'update';
            self.dialog1.fromData.planArriveTime=self.dialog1.fromData.planArriveTime?self.timestampToTime1(self.dialog1.fromData.planArriveTime,'yy-mm-dd hh:mm:ss'):null;
            self.dialog1.fromData.planPayTime=self.dialog1.fromData.planPayTime?self.timestampToTime1(self.dialog1.fromData.planPayTime,'yy-mm-dd hh:mm:ss'):null;
            if(self.dialog1.title==='新增'){
                self.dialog1.fromData.tid = self.dialog.fromData.id;
            }
            cgbHttp.addUpdateCgTaskDetail(type,self.dialog1.fromData).then(res=>{
                self.dialog1.isShow = false;
                self.getProcessStateData();
                self.$message.success(`${self.dialog1.title}成功`);
            })
        },
        showDialog2(type,row){
            let self = this;
            self.dialog2.id=String(row.id);
            if(type==='order'){
                self.$refs.print1.getCgPdfData(row.id);
            }else{
                 self.$refs.print2.getCgPdfData(row.id);
            }

        },
        sendMail(row){
            let self = this;
            let htmlContent = String(self.$refs.pdfDom);
             const loading = this.$loading({
                lock: true,
                text: '正在发送中，请稍后...',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
            cgbHttp.sendEmail({
                contentId:row.id
            }).then(res=>{
                loading.close();
                self.$message.success('发送成功');
            },error=>{
                loading.close();
            })
        },
         paymentMethodFormatter(row, column, cellValue, index){
            let self = this;
            let name = '';
            self.payTypeList.forEach(item=>{
                if(Number(item.code) === cellValue){
                   name =item.name;
                }
            })
            return name;
        },
        beforeAvatarUpload(file){/**图片上传前图片大小验证*/
            const isJPG = file.type.substr(0,5) === 'image';
            const isLt10M = file.size / 1024 / 1024 < 10;
            if (!isJPG) {
                this.$message.error('只能上传图片!');
            }
            if (!isLt10M) {
                this.$message.error('上传头像图片大小不能超过 10MB!');
            }
            return isJPG && isLt10M
        },
         handleAvatarSuccess1(response, file, fileList){
            this.dialog.fromData.payEvidence = response;
        },
        handleAvatarSuccess2(response, file, fileList){
             this.dialog.fromData.receiveEvidence = response;
        },
        clickArrive(row){
            let self = this;
            self.$confirm('是否确认到货?', '提示', {
            confirmButtonClass: 'el-button--warning'
            }).then(() => {
                let type = self.dialog1.title==='新增'?'insert':'';
            row.planArriveTime=row.planArriveTime?self.timestampToTime1(row.planArriveTime,'yy-mm-dd hh:mm:ss'):null;
            row.planPayTime=row.planPayTime?self.timestampToTime1(row.planPayTime,'yy-mm-dd hh:mm:ss'):null;
            row.actNums =row.nums;
            row.isBuy=1;
            cgbHttp.addUpdateCgTaskDetail('update',row).then(res=>{
                self.getProcessStateData();
                self.$message.success(`到货成功`);
            })
            }).catch(() => {})
        },
        deleteBack(row){
            let self = this;
            self.$confirm('是否退回重新审核?', '提示', {
            confirmButtonClass: 'el-button--warning'
            }).then(() => {
            cgbHttp.cgTaskBackCheck(row.id).then(res=>{
                self.getProcessStateData();
                self.$message.success(`退回成功`);
            })
            }).catch(() => {})

        }
    }
}
</script>
<style scoped>
.pdfBox{
    margin-top:-56px;
}
.orderGoodsTable{
    margin-top:24px;
}

.discrtion{
    font-size: 14px;
    margin:24px 0;
}
.discrtion .discrtion-title{
    font-weight: bold;
}
.cl-success{
    line-height: 100%;
    font-size:18px;
}
.boxTb{
    border-top: 1px solid rgb(0, 0, 0);
    padding:0 10px;
}
.labelTitle{
    line-height: 200px;
    font-size: 15px;
}
.uploadImg{
    height:200px;
    overflow: hidden;
    padding:10px 24px;
    box-sizing: border-box;
}
.uploadImg .avatar-uploader{
    height:100%;
    text-align: center;
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.uploadImg .avatar-uploader:hover{
border-color: #409EFF;
}
.uploadImg .avatar-uploader .el-icon-plus::before{
    display: block;
    font-size: 24px;
    margin-top:67px;
}
.avatar {
    max-width: 100%;
    max-height:180px ;
    display: block;
    margin:auto;
  }
</style>

